package com.zx.zxapibackend.service.impl.inner;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zx.zxapibackend.model.domain.Auth;
import com.zx.zxapibackend.model.domain.User;
import com.zx.zxapibackend.service.AuthService;
import com.zx.zxapibackend.service.UserService;
import com.zx.zxapicommon.common.BaseResponse;
import com.zx.zxapicommon.exception.BusinessException;
import com.zx.zxapicommon.model.enums.ErrorCode;
import com.zx.zxapicommon.service.InnerUserService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 张旭
 * @version 1.0
 */
@DubboService
public class InnerUserServiceImpl implements InnerUserService {
    @Resource
    private UserService userService;

    @Resource
    private AuthService authService;

    @Override
    public com.zx.zxapicommon.model.entity.User getInvokeUser(String accessKey) {
        if (StringUtils.isAnyBlank(accessKey)) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数为空");
        }

        QueryWrapper<Auth> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.eq("accessKey", accessKey);


        Auth one = authService.getOne(userQueryWrapper);
        Long userid = one.getUserid();
        User invokeUser = userService.getById(userid);
        com.zx.zxapicommon.model.entity.User user = BeanUtil.copyProperties(invokeUser, com.zx.zxapicommon.model.entity.User.class);
        return user;
    }


}